package com.example.bes.springboot.web.war.fliter;

import cn.dev33.satoken.util.SaTokenConsts;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Sa-Token 兼容过滤器配置
 */
@Configuration
public class SaTokenFilterConfig {

    @Bean
    public FilterRegistrationBean<SaTokenFilterWrapper> saTokenCompatFilter() {
        FilterRegistrationBean<SaTokenFilterWrapper> bean = new FilterRegistrationBean<>();
        bean.setFilter(new SaTokenFilterWrapper());
        bean.setName("saTokenContextFilterForServlet");
        bean.addUrlPatterns("/*");
        // 保留 Sa-Token 原来的优先级顺序
        bean.setOrder(SaTokenConsts.SA_TOKEN_CONTEXT_FILTER_ORDER);
        return bean;
    }

    @Bean
    public FilterRegistrationBean<SaTokenFilterWrapper2> saTokenCompatFilter2() {
        FilterRegistrationBean<SaTokenFilterWrapper2> bean = new FilterRegistrationBean<>();
        bean.setFilter(new SaTokenFilterWrapper2());
        bean.setName("saFirewallCheckFilterForServlet");
        bean.addUrlPatterns("/*");
        // 保留 Sa-Token 原来的优先级顺序
        bean.setOrder(SaTokenConsts.SA_TOKEN_CONTEXT_FILTER_ORDER);
        return bean;
    }

    @Bean
    public FilterRegistrationBean<SaTokenFilterWrapper3> saTokenCompatFilter3() {
        FilterRegistrationBean<SaTokenFilterWrapper3> bean = new FilterRegistrationBean<>();
        bean.setFilter(new SaTokenFilterWrapper3());
        bean.setName("saTokenCorsFilterForServlet");
        bean.addUrlPatterns("/*");
        // 保留 Sa-Token 原来的优先级顺序
        bean.setOrder(SaTokenConsts.SA_TOKEN_CONTEXT_FILTER_ORDER);
        return bean;
    }
}
